package day20180131.designMode.nine_Decorator;

/**
 * Created by 14394 on 2018/1/31.
 */
//源实现类
public class SourceImp implements Source {



    @Override
    public void method() {
        System.out.println("SourceImp method have run!");
    }
}

//装饰类(写在这里是为了方便比对)
class Decorator implements Source{



    private Source source;

    public Decorator(Source source){
        super();
        this.source = source;
    }

    @Override
    public void method() {
        System.out.println("Decorator method before");
        source.method();
        System.out.println("Decoretor method after");
    }



    /*使用场景：  需要扩展一个类的功能，或者给一个类增加附加功能
    *            需要动态的增加功能，并且能够动态的撤销
    *            需要对一批兄弟类及进行改装或者加装功能首选装饰模式
    *          */
    public static void main(String[] args) {
        Source source = new SourceImp();
        Source decorator = new Decorator(source);
        decorator.method();
    }
}
